package cn.zwx.learn.basic.groovy;

import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import cn.zwx.learn.basic.groovy.utils.GroovyUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @description:
 * @projectName:java-basic
 * @see:groovy
 * @author:zhangwenxue
 * @createTime:2021/4/14 13:14
 * @version:1.0
 */
@RestController
public class GroovyController {

    @Autowired
    private LoadGroovyService loadGroovyService;
    
    @GetMapping("/groovy")
    public String testGroovy(){
        HashMap<Object, Object> params = new HashMap<>();
        params.putIfAbsent("currentDate", DateTime.now());
        return JSON.toJSONString(GroovyUtil.invoke("rule_1",params));
    }

    @GetMapping("/refresh")
    public String refreshSpringContentDueToGroovy() throws Exception {
        loadGroovyService.refreshSpringContentDueToGroovy("action.test.Cls_rule_2");
        return "处理成功";
    }
}
